package com.my.lab.activity;

import com.my.lab.R;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;

public class WebViewActivity extends Activity{

    WebView view ;
    private ProgressBar pb ;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);
        view = (WebView) findViewById(R.id.myview);
        int width = getWindowManager().getDefaultDisplay().getWidth();
        pb = (ProgressBar) findViewById(R.id.bottom_bar);
        if (width < 320) {
            view.getSettings().setBuiltInZoomControls(true);
        }
        view.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                Log.d("onProgressChanged",""+ newProgress);
                pb = (ProgressBar) findViewById(R.id.bottom_bar);
                if (newProgress < 100) {
                    if (pb.getVisibility() == View.GONE) {
                        pb.setVisibility(View.VISIBLE);
                    }
                    pb.setProgress(newProgress); 
                } else {
                    pb.setProgress(100);
                    pb.setVisibility(View.GONE);
                }
            }
        });
        String url  = "http://ww2.sinaimg.cn/large/9304f645gw1dxy3djiqpyj.jpg";
        String data = "<center><img src=\""+url+"\" width = \"320\"></center>" ;
        view.loadData(data, "text/html", "utf-8");
    }
    
}
